<div id="formSuccess" style="display: none">{if isset($formSuccess)}currentPage{/if}</div>
{assign var=lang value=$media->getLang()}
{assign var=id value=$media->getUniqueId()}
<form name="mediaEdit" action="?module=medias&action=block_Edit&mediaId={$media->getUniqueId()}&docLang={$media->getLang()}" class="nyroModal" method="post">

{include file="$MODULES_DIR/backoffice/templates/block/modal/ModalTitle.html" title=$media->getLabel()}
{literal}
<style type="text/css">
    table.listTable td{
        border: 0;
    }
    
    td{
        vertical-align:middle;
    }

    table.infoGen, table.infoGen tr, table.infoGen td, table.infoGen th{
        border: 0;
        background: none;
    }

    table.infoGen th{
        width: 120px !important;
        text-align: left;
        height: 26px;
        line-height: 26px;
    }
    table.infoGen td{
        padding-top: 5px;
    }
    table.infoGen tr{
        border-bottom: 1px #2F2F2F dotted;
        border-left: 1px #2F2F2F solid;
        background-color: #272727;
    }
    table.infoGen tr:hover{
        background-color: #2F2F2F;
    }

</style>
{/literal}

<div id="modalContent" style="min-width: 980px;">
<div id="tabContent">
    <!-- Info base -->
        <input type="hidden" name="form[folderId]" value="{$folder->getUniqueId()}" />
        <input type="hidden" name="form[folderLang]" value="{$folder->getLang()}" />
        <table class="form">
            <tr>
                <td style="text-align:center;">
                    <div id="modalFileName">{if $media->isLink()}<a href="{$media->getLabel()}" target="_new">{$media->getTitle()}</a>{else}{$media->getLabel()}{/if}</div>
                    <div id="modalActionLine">
                        {hasRight rule=medias_Delete}
                        {hasDocRight document=$media module="medias" rule="delete"}
                        <span style="width: 20px; height: 20px; ">
                            <a href="?module=backoffice&action=AjaxContext&href={url route='deleteMedias' docId=$media->getUniqueId() docLang=$media->getLang()}" class="nyroModal openModal itemButton itemDeleteButton" onclick=""></a>
                        </span>
                        {/hasDocRight}
                        {/hasRight}
                        <span style="width: 20px; height: 20px; ">
                            <a href="?module=backoffice&action=AjaxContext&href={url route='mediaViewImage' docId=$media->getUniqueId() docLang=$media->getLang() width='default' height='default'}" class="nyroModal openModal itemButton itemViewButton defaultAction"></a>
                        </span>
                    </div>
                    <table>
                        <tr>
                            {if $previousImage != null}<td rowspan="5" style="width: 20px; vertical-align: middle; padding: 5px;"><a href="?module=backoffice&action=AjaxContext&href={$previousImage->getEditUrl($folder->getUniqueId())}" class="nyroModal openModal arrowButton arrowButtonLeft"></a></td>{else}<td rowspan="5" style="width: 20px; vertical-align: middle; padding: 5px;"></td>{/if}
                            <td style="padding-top: 26px;" width="400">
                                <a href="?module=backoffice&action=AjaxController&href={url route='mediaViewImage' docId=$media->getUniqueId() docLang=$media->getLang() width='default' height='default'}" class="nyroModal openModal">
                                    {if $media->isImage()}
                                        <img src="{$media->getPreview(true)}" />
                                    {elseif $media->isLink()}
                                        {$media->getLinkPreview()}
                                    {else}
                                        {icon name=$media->getIcon(false, false, '9696') size='96'}
                                    {/if}
                                </a>
                            </td>
                            {if $nextImage != null}<td rowspan="5" style="width: 20px; vertical-align: middle; padding: 5px;"><a href="?module=backoffice&action=AjaxContext&href={$nextImage->getEditUrl($folder->getUniqueId())}" class="nyroModal openModal arrowButton arrowButtonRight"></a></td>{else}<td rowspan="5" style="width: 20px; vertical-align: middle; padding: 5px;"></td>{/if}
                        </tr>
                    </table>
                </td>
                <td style="vertical-align:top;">
                    <table class="infoGen" width="100%">
                        <tr>
                            <th>{t}Title{/t} : </th>
                            <td>
                                <input type="text" name="form[title]" value="{$media->getTitle()}" style="width:300px" />
                                {if isset($errors.title)}<div>{icon name="warning.png"} {$errors.title}</div>{/if}
                            </td>
                        </tr>
                        <tr>
                            <th>{t}Alternative text{/t} : </th>
                            <td>
                                <input type="text" name="form[alt]" value="{$media->getAlt()}" style="width:300px" />
                            </td>
                        </tr>
                        <tr>
                            <th>{t}Information{/t} : </th>
                            <td>{if $media->isImage()}{$media->getWidth()} x {$media->getHeight()} pixels{else}/{/if} &nbsp;&nbsp;&nbsp; {$media->getSize()} &nbsp;&nbsp;&nbsp; {date date=$media->getCreationDate() smartformat="localized-data-time-format"}</td>
                        </tr>
                        <tr>
                            <th>{t}Status{/t} : </th>
                            <td>
                                <select name="form[status]" id="statusSelectBox">
                                    <option value="DRAFT" {if $media->getPublicationstatus() == "DRAFT"}selected="selected"{/if}">{t}Unpublished{/t}</option>
                                    <option value="PUBLISHED" {if $media->getPublicationstatus() == "PUBLISHED"}selected="selected"{/if}>{t}Published{/t}</option>
                                </select>
                            </td>
                        </tr>
                        <tr style="border-bottom: 1px solid #2F2F2F;"><td colspan="2">&nbsp;</td></tr>
                    </table>
                    {if $media->isImage()}
                    <table class="tabMedia" width="100%">
                        <tr class="tabMediaHeader">
                            <td colspan="3">{icon name="dark_arrow_down.png" title="Autres format"} {t}OTHER DIMENSIONS{/t}</td>
                            <td class="addOptionMed">
                                <!--{$media->countResizedImages()-1}-->
                                <div id="nyroAddFormat">
                                <a href="javascript:void(0);" onclick="centeredPopup('{$URL_RELATIVE}/index.php?module=medias&action=AjaxEditImage&folderId={$folder->getUniqueId()}&docId={$media->getUniqueId()}&docLang={$media->getLang()}&opener=editmedia','Edition', 1024, 768);" class="">
                                    {t}Add dimension{/t}
                                </a>
                                </div>
                            </td>
                        </tr>
                        {foreach from=$files item=file name=files}
                        {assign var='dim' value=$file->getDimensions()}
                        <tr>
                            <td>{$dim.0} x {$dim.1} pixels{if $file->getFileName() == $media->getFileNameWoExt()} ({t}original{/t}){/if}</td>
                            <td>{$file->getFilesizeFormatted()}</td>
                            <td>{$file->getCreationDate()}</td>
                            <td>
                                <span class="listButtons">
                                {if $file->getFileName() != $media->getFileNameWoExt()}
                                <a href="javascript:void(0)" onclick="deletePicture('{$media->getUniqueId()}', '{$media->getLang()}','{$file->getFileName()}.{$file->getExtension()}');" class="itemButton itemDeleteButton"></a>
                                {/if}
                                {if $file->getFileName() != $media->getFileNameWoExt()}
                                <a href="index.php?module=backoffice&action=AjaxContext&href={url route='mediaViewImage' docId=$media->getUniqueId() docLang=$media->getLang() width=$dim.0 height=$dim.1}" class="nyroModal openModal itemButton itemViewButton defaultAction"></a>
                                {else}
                                <a href="index.php?module=backoffice&action=AjaxContext&href={url route='mediaViewImage' docId=$media->getUniqueId() docLang=$media->getLang() width='default' height='default'}" class="nyroModal openModal itemButton itemViewButton defaultAction"></a>
                                {/if}
                                </span>
                            </td>
                        </tr>
                        {/foreach}
                    </table>
                    {/if}
                    <table class="tabMedia" width="100%">
                        <tr class="tabMediaHeader">
                            <td colspan="3">{t assignTo=iconTitle}Link media{/t}{icon name="dark_arrow_down.png" title=$iconTitle} {t}LINK MEDIA{/t}</td>
                            <td class="addOptionMed">
                                <div style="display: none" id="mediaEditUrl">{$media->getEditUrl($folder->getUniqueId())}</div>
                                <!--{$linkedMediaNb}-->
                                <div id="nyroAddFormat">
                                <a href="javascript:void(0);" class="addImg media" title="{t}Select media{/t}">
                                    {t}Add media{/t}
                                </a>
                                </div>
                            </td>
                        </tr>
                        {foreach from=$linkedMedia item=media}
                        <tr id="{$media->getUniqueId()}">
                            <td>
                                <td>
                                    {if $media->isImage()}<img src="{$media->getIcon(true)}" class="icon16" />{else}{icon name=$media->getIcon()}{/if}</span> {$media->getLabel()}
                                     - {$media->getSize()} -
                                    {if $media->isImage()}{$media->getWidth()} x {$media->getHeight()} pixels{else}/{/if}
                                </td>
                                <td>
                                    {$media->getFormattedMimeType()}
                                </td>
                                <td>
                                    <span class="listButtons">
                                        <a href="javascript:void(0)" onclick="linkImg({$media->getUniqueId()}, '{$media->getLabel()}', 'unlink');" class="itemButton itemDeleteButton"></a>
                                    </span>
                                </td>
                        </tr>
                        {/foreach}
                    </table>
                    <table class="tabMedia" width="100%">
                        <tr class="tabMediaHeader">
                        <td>{icon name="dark_arrow_down.png" title="Options"} {t}OPTIONS{/t}</td>
                        </tr>
                        <tr>
                            <td class="tabMediaNoStyle">
                                <label>{t}Description{/t}</label><br/>
                                <textarea class="nyroTextAreaDesc" name="form[description]" cols="70">{$media->getDescription()}</textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>        
        </table>
        <input type="hidden" id="checkSubmit" name="form[submit]" value="false" />
    </div>
</div>
{include file="$MODULES_DIR/backoffice/templates/block/modal/ModalFooter.html" onClickParam="tinyMCE.triggerSave();$('#checkSubmit').attr('value','true');"}
</form>

<script type="text/javascript">
    {literal}

    $('.tabMedia tr').hover(function(){
        $(this).children('td').children('.listButtons').css('visibility', 'visible');
    }, function(){
        $(this).children('td').children('.listButtons').css('visibility', 'hidden');
    });

    if($('#formSuccess').html() == 'currentPage')
    {
        $.nyroModalRemove();
        $.historyLoad(getHash(document.location.toString()), {refresh:true});
    }

    function refreshFormats()
    {
        {/literal}
        $.nyroModalRemove();
        showModal("?module=backoffice&action=AjaxContext&href=/medias/edit/{$media->getLang()}/{$folder->getUniqueId()}/{$media->getUniqueId()}/properties");
        {literal}
    }


    // FIX FOR NYROMODAL
    $(function() {
        $.fn.nyroModal.settings.processHandler = function(settings) {
            var from = settings.from;
            if (!settings.type && from && from.href) {
                var arr = from.href.split('?');
	
                if(arr.length>1){
                    var newArr=arr[0].split('.');
                    var newType=settings.type;
	
                    switch(newArr[newArr.length-1].toUpperCase()){
                        case 'IMG':
                        case 'JPG':
                        case 'JPEG':
                        case 'PNG':
                        case 'GIF':
                            newType='image';
                            break;
                        default:
                            newType=settings.type;
                    }
					
                    $.nyroModalSettings({
                        type: newType//
                    });
                }
            }
        };
    });
	
    $(".openModal").nyroModal({
        minHeight: 10,
        minWidth: 10,
        closeButton: '',
        bgColor: '#D4D0C8'
    });
    {/literal}
</script>
